<?php

vendor('mail/mail_model');

$_this =& $this;

/* @var $_this View */
/* @var $form FormHelper */
/* @var $editForm EditFormHelper */
/* @var $html HtmlHelper */
/* @var $ehtml EHtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $jqax JqaxHelper */
/* @var $filterBlock FilterBlock */

?><?=$filterBlock->create('Filter', array('url'=>("/{$url_part}/")));?><?php

	$filterBlock->add(
        $form->label('from_date', __d($po_domain, 'created_field', true).': '.mb_strtolower(__d(null, 'from_period', true), DEFAULT_CHARSET).' ',array('class'=>'filter')).
		$calendar->date('from_date', false, array('size' => '10', 'label' => false)).
		' '.
		$form->label('to_date', __d(null,'to_period', true).' ',array('class'=>'filter')).
		$calendar->date('to_date', false, array('size' => '10', 'label' => false))
	);
?><?=$filterBlock->end();?><?php

?><br /><?php

if (count($list->rows)) {

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

?><table class="table" cellpadding="0"><?php
?><thead><?php
    ?><tr><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'created', 'msg'=>'created', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'retries', 'msg'=>'retries', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=__d($po_domain, 'recepient', true);?><?php
        ?></th><?php
    ?></tr><?php
?></thead><?php
?><tbody><?php

    $i = 0;
    foreach ($list->rows as $item) {
        $class = '';
    	if ($i++ % 2 != 0) {
    		$sep = strlen($class) ? ' ' : '';
    		$class .= $sep.'altrow';
    	}
    	$class = strlen($class) ? ' class="'.$class.'"' : '';

        ?><tr <?=$class;?>><?php
    		?><td class="nw"><?php
                ?><?=Date::Short(Date::SQL2UNIX($item[$modelName]['created']));?><?php
            ?></td><?php
    		?><td class="nw"><?php
        		if (!empty($item[$modelName]['retries'])) {
                    ?><?=$item[$modelName]['retries'];?><?php
        		} else {
                    ?>—<?php
        		}
            ?></td><?php
    		?><td class="nw"><?php
        		if (is_object($item[$modelName]['data']) && ($item[$modelName]['data'] instanceof MailModel)) {
                    $to_email = $item[$modelName]['data']->to;
                    ?><?=$html->link($to_email, 'mailto:'.$to_email)?><?php
        		}
            ?></td><?php
    	?></tr><?php
    }

?></tbody><?php
?></table><?php

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

} else {
    ?><span class="additional_msg"><?php
        ?><?=__d($po_domain, 'List is empty', true);?><?php
    ?></span><?php
}

?>